<!--
* description: 销退管理-销退申请
* author: ligy
* createdDate: 2020-11-23
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="dynamicApiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :dynamic-is-column-drop="true"
      :is-set-default-brand="false"
      :dynamic-is-fix-choose="false"
      :dynamic-is-fix-index="false"
      :dynamic-api-style="'restful'"
    />

    <Edit
      v-if="editPopupsVisible"
      :key="editPopupsKey"
      :popups-visible.sync="editPopupsVisible"
      :data-for-form="editRowData"
      :popups-state="editPopupsState"
      :title-name="titleName"
      @updation="updation"
    />
  </div>
</template>

<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import Edit from './edit'
import api from '@/api/vehicleManagement'
import commFields from '@/views/ve/testDriverManage/common'

// v-if="editPopupsVisible"
//      @close="close"

export default {
  components: {
    OneTableTemplate,
    Edit
  },
  mixins: [oneTableWithViewTemplateMixins],
  data() {
    return {
      titleName: '',
      editRowData: {},
      editPopupsState: '',
      editPopupsVisible: false,
      detPopupsVisible: false,
      dynamicApiConfig: api.refundApplication,
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            // 操作
            // {
            //   prop: '',
            //   label: '操作',
            //   align: 'center',
            //   width: 200,
            //   fixed: false,
            //   isComponent: true,
            //   comps: [
            //     {
            //       compKey: 'propKey0',
            //       labelName: '修改',
            //       codeField: '',
            //       clickEvent: index => this.edit('edit', index),
            //       component: () => import('@/components/org/linkButton')
            //     },
            //     {
            //       compKey: 'propKey1',
            //       labelName: '提交',
            //       codeField: '',
            //       clickEvent: index => this.edit(index),
            //       component: () => import('@/components/org/linkButton')
            //     },
            //     {
            //       compKey: 'propKey2',
            //       labelName: '作废',
            //       codeField: '',
            //       clickEvent: index => this.delData(index),
            //       component: () => import('@/components/org/linkButton')
            //     },
            //     {
            //       compKey: 'propKey3',
            //       labelName: '附件上传',
            //       clickEvent: index => this.checkFile(index),
            //       codeField: '',
            //       component: () => import('@/components/org/linkButton')
            //     }
            //   ]
            // },
            {
              prop: 'saleOrderRetrunCode',
              label: '销退申请单号',
              width: 150
            },
            {
              prop: 'saleOrderTypeName',
              label: '类型'
            },
            {
              prop: 'returnStateName',
              label: '状态'
            },
            {
              prop: 'applyDate',
              label: '申请日期',
              width: 120
            },
            {
              prop: 'saleOrderFee',
              label: '退货金额'
            },
            {
              prop: 'saleOrderReasonName',
              label: '退货申请原因',
              width: 150
            },
            {
              prop: 'saleOrderCode',
              label: '关联订单号'
            },
            ...commFields.ModelOptionsTableCol()
          ],
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            // 退货类型
            {
              compKey: 'compKey1',
              labelName: '类型：',
              codeField: 'saleOrderType',
              component: () => import('@/components/org/commonSelect'),
              lookuptype: 'VE0031',
              isMust: true
            },
            // 申请单号
            {
              compKey: 'compKey2',
              labelName: '销退申请单号：',
              codeField: 'saleOrderRetrunCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            // 关联订单号
            {
              compKey: 'compKey3',
              labelName: '关联订单号：',
              codeField: 'saleOrderCode',
              // component: () => import('@/components/org/associatedOrderNumber'),
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            // 申请日期
            {
              compKey: 'compKey4',
              labelName: '申请日期：',
              codeField: 'applyStartTime,applyEndTime',
              component: () => import('@/components/org/datePicker/datePicker'),
              dateType: 'daterange',
              isMul: false,
              isMust: true
            },
            ...commFields.ModelOptionsNotDisabled()
          ],
      tableButtons: [
        {
          conmpKey: 'btenKey1',
          type: '',
          size: 'small',
          text: '新增',
          clickEvent: (index) => this.add('add', index),
          position: 'left'
        },
        {
          conmpKey: 'btenKey2',
          type: 'primary',
          size: 'small',
          text: '查询',
          clickEvent: () => this.queryTable(1),
          position: 'right'
        },
        {
          conmpKey: 'btenKey3',
          type: '',
          size: 'small',
          text: '重置',
          clickEvent: () => this.reset(),
          position: 'right'
        }
      ],
      formField: this.$utils.getFormField(this, {
        saleOrderType: '',
        saleOrderRetrunCode: '',
        saleOrderCode: '',
        orderDlrCode: '',
        orderDlrName: '',
        returnStateCode: '',
        carSeriesId: '',
        carConfigId: '',
        carConfigCn: '',
        carSeriesCn: '',
        optionalPagId: '',
        carColorId: '',
        carIncolorId: '',
        applyStartTime: '',
        applyEndTime: ''
      })
    }
  },
  mounted() {
    this.queryTable(1)
  },
  methods: {
    updation() {
      this.queryTable(1)
    },
    closedet() {
      this.detPopupsVisible = false
    },
    details(index) {
      this.detPopupsVisible = true
      this.editRowData = this.$refs.multipleTable.list[index]
    },
    edit(type, idx) {
      if (type == 'edit') {
        this.titleName = '销退申请清单编辑'
      }
      this.editPopupsVisible = true
      this.editRowData = this.$refs.multipleTable.list[idx]
      console.log(this.editRowData)
    },
    add(type, idx) {
      if (type == 'add') { this.titleName = '销退申请清单制作' }
      this.editPopupsVisible = true
      this.editRowData = {}
    },
    delData(index) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // requestRestful({
        //   apiUrl: '',
        //   variables: {},
        //   method: 'POST', // 默认post
        //   contentType: '', // 默认 'application/json; charset=UTF-8'
        //   lock: '',
        //   urlType: 'GET' // 处理非json请求
        // })
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 查看附件
    checkFile(index, type) {
      // location.href = process.env.VUE_APP_BASE_API + this.$refs['multipleTable'].list[index].downloadUrl
      // window.open(this.$refs['multipleTable'].list[index][type])
    },
  }
}
</script>

<style></style>
